﻿// code05060200.cpp : 异常处理
// try-catch语句

#include <iostream>
#include "..\code05060100\Sales_item.h"
#include <stdexcept>
using namespace std;
int main()
{
	Sales_item item1, item2;
	cout << "输入两个sales_item对象" << endl;
	while (cin>>item1>>item2)
	{
		try
		{
			if (item1.isbn() != item2.isbn())
			{
				throw runtime_error("数据必须是相同型号");
			}
			cout << item1 + item2 << endl;
		}
		catch (runtime_error err)
		{
			cout << err.what()<<endl;
			cout << "再次输入？y/n :";
			char c;
			cin >> c;
			if (!cin||c=='n')
			{
				break;				//跳出while循环
			}

		}
	}
	return 0;
}


